#!/usr/bin/env node

const Koa = require('koa'),
      log = console.log;

const app = new Koa();

//ctx 上下文； next 调用后面的中间件 

app.use((ctx,next) => {              //M-logger
  //parse req
  log(`${ctx.method} ${ctx.path}`);
  next();
  //response
});

app.use((ctx,next) => {              //M-ms
  const start = Date.now();
  next();
  const end = Date.now();
  log(`cost:${end-start}ms`);
});

app.use((ctx,next) => {              //M-hello
  ctx.body = 'hello koa';
});
app.listen(8080);

//console.log('hello world;
